package com.itheima.health.security;

import com.itheima.health.entity.Result;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author by Dragon
 * @Classname 未登录访问处理器
 * @Description TODO
 * @Date 2020/2/26 1:10
 * @Version 1.0
 */
public class MyAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException, ServletException {
        request.getRequestDispatcher("/user/needLogin.do")
                .forward(request,response);
        //response.getWriter().println(new Result(false,"需要登录...3秒后跳转..."));
        //response.setHeader("refresh","3;url=http://localhost:9090/page/login.html");

    }
}
